package com.sidianzhong.sdz.service.impl;

import com.github.pagehelper.PageHelper;
import com.sidianzhong.sdz.mapper.*;
import com.sidianzhong.sdz.model.*;
import com.sidianzhong.sdz.service.*;
import com.sidianzhong.sdz.utils.PageInfo;
import com.sidianzhong.sdz.utils.Tools;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.*;


/**
* Created by hxgqh on 2016/1/7.
*/
@Service
@Transactional
public class WebHequipmentgroupServiceImpl implements WebHequipmentgroupService{
    protected static final Logger LOG = LoggerFactory.getLogger(WebHequipmentgroupServiceImpl.class);

    // 将所有的modelMapper注入
    @Autowired
    private WebHequipmentgroupMapper webHequipmentgroupMapper;


    @Override
    public WebHequipmentgroup create(WebHequipmentgroup item) {

         webHequipmentgroupMapper.insert(item);
         return item;
    }

    @Override
    public int delete(Integer id) {
        return webHequipmentgroupMapper.deleteByPrimaryKey(id);
    }

    @Override
    public int update(WebHequipmentgroup item) {

        return webHequipmentgroupMapper.updateByPrimaryKeySelective(item);
    }

    @Override
    public WebHequipmentgroup get(Integer id) {
        return webHequipmentgroupMapper.selectByPrimaryKey(id);
    }
    @Override
     public PageInfo<WebHequipmentgroup> getListWithPaging(Integer pageNum, Integer pageSize,
                                                  String sortItem, String sortOrder,WebHequipmentgroup item){

        WebHequipmentgroupExample  example = new WebHequipmentgroupExample();
        WebHequipmentgroupExample.Criteria criteria = example.createCriteria();
        if(item.getSitename() != null ){
            criteria.andSitenameEqualTo(item.getSitename());
        }
        if(item.getEquipmenttypekey() != null ){
            criteria.andEquipmenttypekeyEqualTo(item.getEquipmenttypekey());
        }
        if(item.getEquipmentname() != null ){
            criteria.andEquipmentnameEqualTo(item.getEquipmentname());
        }
        if(item.getEquipmentkey() != null ){
            criteria.andEquipmentkeyEqualTo(item.getEquipmentkey());
        }
        if(item.getStatus() != null ){
            criteria.andStatusEqualTo(item.getStatus());
        }
        if(item.getEquipmentip() != null ){
            criteria.andEquipmentipEqualTo(item.getEquipmentip());
        }
        if(item.getAgreementtype() != null ){
            criteria.andAgreementtypeEqualTo(item.getAgreementtype());
        }
        if(item.getBindtype() != null ){
            criteria.andBindtypeEqualTo(item.getBindtype());
        }
        if(item.getEquipmentport() != null ){
            criteria.andEquipmentportEqualTo(item.getEquipmentport());
        }
        if(item.getEquipmentid() != null ){
            criteria.andEquipmentidEqualTo(item.getEquipmentid());
        }
        if(item.getTablename() != null ){
            criteria.andTablenameEqualTo(item.getTablename());
        }
        if(item.getItemname() != null ){
            criteria.andItemnameEqualTo(item.getItemname());
        }
        if(item.getWarmingdata() != null ){
            criteria.andWarmingdataEqualTo(item.getWarmingdata());
        }
        if(item.getMaintransmittername() != null ){
            criteria.andMaintransmitternameEqualTo(item.getMaintransmittername());
        }
        if(item.getMaintransmitterkey() != null ){
            criteria.andMaintransmitterkeyEqualTo(item.getMaintransmitterkey());
        }
        if(item.getSparetransmittername() != null ){
            criteria.andSparetransmitternameEqualTo(item.getSparetransmittername());
        }
        if(item.getSparetransmitterkey() != null ){
            criteria.andSparetransmitterkeyEqualTo(item.getSparetransmitterkey());
        }
        if(item.getMaintransmitterpowertype() != null ){
            criteria.andMaintransmitterpowertypeEqualTo(item.getMaintransmitterpowertype());
        }
        if(item.getSparetransmitterpowertype() != null ){
            criteria.andSparetransmitterpowertypeEqualTo(item.getSparetransmitterpowertype());
        }
        if(item.getIfmonitor() != null ){
            criteria.andIfmonitorEqualTo(item.getIfmonitor());
        }
        if(item.getEquipmentmodel() != null ){
            criteria.andEquipmentmodelEqualTo(item.getEquipmentmodel());
        }

        example.setOrderByClause(Tools.humpToLine(sortItem)+" "+sortOrder);
        PageHelper.startPage(pageNum, pageSize);
        List< WebHequipmentgroup> list = this.webHequipmentgroupMapper.selectByExample(example);
        PageInfo result = new PageInfo(list);

        return result;

     }

    @Override
    public WebHequipmentgroup getByKey(String equipmenttypekey, String equipmentkey) {
        return this.webHequipmentgroupMapper.getByKey(equipmenttypekey,equipmentkey);
    }

    @Override
    public List<WebHequipmentgroup> getList() {
        WebHequipmentgroupExample  example = new WebHequipmentgroupExample();
        List< WebHequipmentgroup> list = this.webHequipmentgroupMapper.selectByExample(example);
        return list;
    }

}
